<?php

class PageDirectory extends Page
{
	public function getHTML()
	{
		$html = $this->getHeaderHTML();

		$submitScript = new SubmitFormScript();
		$html .= $submitScript->getHTML();

		$script = new EditDeleteFormScript();
		$html .= $script->getHTML();

		$html .= $this->getBodyTopHTML();
		$html .= $this->getHiddenVariables();

		$View = new Hidden();
		$View->setName("CallingPage");
		$View->setValue('Directory');
		$html .= $View->gethtml();

		$datatable = new DataTable();
		$datatable->setParentPage($this);
		$datatable->setName("Directory");
		$datatable->setValue("Directory");
		$datatable->setEditable(true);
		$datatable->setDeletable(true);
		if(isset($_POST['ShowDeleted']))
			$datatable->showDeleted($_POST['ShowDeleted']);
/*		if(isset($_POST['ShowBefore']))
			$datatable->showBefore($_POST['ShowBefore']);
		if(isset($_POST['ShowAfter']))
			$datatable->showAfter($_POST['ShowAfter']);
		elseif((!isset($_POST['ShowBefore']))&&(!isset($_POST['ShowAfter'])))
			$datatable->showAfter(true);
		if(isset($_POST['ShowLocations']))
			$datatable->showLocations(true);
		if(isset($_POST['ShowEventInvolvees']))
			$datatable->showEventInvolvees(true);
		if(isset($_POST['ShowEventTypes']))
			$datatable->showEventTypes(true);*/
		$datatable->setDBTableName("Persons");
		$datatable->setDatabase($this->Database);
		$theRenderer = new DataTableRendererEdit($datatable);
		$theRenderer->setAction = "Directory";
		$datatable->setRenderer($theRenderer);
		$datatable->setEditDeleteType("Hyperlink");
		$columns = array();
		$columns[] = new DataTableColumn("Name","Name","");
		$columns[] = new DataTableColumn("Address","Address","");
		$columns[] = new DataTableColumn("Phone","Phone Details","");
		$columns[] = new DataTableColumn("Email","Email","");
		$datatable->setColumns($columns);
		$datatable->setSelect("select PersonID as ColumnID, CONCAT(Surname , ', ' , FirstName) as Name, CONCAT(Address1 , '<br>' , Address2 , '<br>' , Address3 , '<br>' , Address4 , '<br>' , PostCode) as Address, CONCAT(MobilePhone , '<br>' , WorkPhone , '<br>' , HomePhone) as Phone, CONCAT(Email1 , '<br>' , Email2) as Email, DeletedBy FROM Persons");
		$datatable->setOrderBy("Surname");

//SET CONDITIONS

// Deleted
		$aCondition = ($datatable->getShowDeleted())?"":" DeletedBy = ''";
		$datatable->addANDCondition($aCondition);


		$html .= $datatable->getHTML();
		$html .= "<br>\n";

		$html .= $this->getBodyBottomHTML();
		return $html;
	}
}
?>